<!--
  To change this template, choose Tools | Templates
  and open the template in the editor.
-->


<%@ page import="baratopradedeu.Pedido" %>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="layout" content="main" />
  <g:set var="entityName" value="${message(code: 'pedido.label', default: 'Pedido')}" />
  <title><g:message code="default.efetuar.label" args="[entityName]" /></title>
</head>
<body>
  <div class="nav">
    <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
    <span class="menuButton"><g:link class="list" controller="oferta" action="list"><g:message code="default.list.label" args="['oferta']" /></g:link></span>
  </div>
  <div class="body">
    <h1><g:message code="default.efetuar.label" args="[entityName]" /></h1>
    <g:if test="${flash.message}">
      <div class="message">${flash.message}</div>
    </g:if>
    <g:hasErrors bean="${pedidoInstance}">
      <div class="errors">
        <g:renderErrors bean="${pedidoInstance}" as="list" />
      </div>
    </g:hasErrors>

    <g:if test="${!ofertaInstance}">
      <br/>
      <a href="${flash.pagina}">Ops!! Nenhuma oferta foi carregada! Retornar.</a>
    </g:if>
    
    <g:form action="salvarCompra" method="post">
      <g:hiddenField name="ofertaId" value="${ofertaId}" />
	  <g:hiddenField name="oferta.id" value="${ofertaId}" />
	  <g:hiddenField name="clienteId" value="${session.cliente.id}" />	 
      <div class="dialog">
        <table>
          <tbody>

            <tr class="prop">
              <td valign="top" class="name">
                <label for="dataPedido"><g:message code="pedido.dataPedido.label" default="Data Pedido" /></label>
              </td>

              <td valign="top" class="value ${hasErrors(bean: pedidoInstance, field: 'dataPedido', 'errors')}">
                <g:formatDate name="dataPedido" format="dd/MM/yyyy" precision="day" value="${pedidoInstance?.dataPedido}"  />
              </td>
            </tr>

			  <tr class="prop">
				<td valign="top" class="name"><g:message code="oferta.titulo.label" default="Titulo" /></td>
				<td valign="top" class="value">${fieldValue(bean: ofertaInstance, field: "titulo")}</td>            
			  </tr>
			   <tr class="prop">
					<td valign="top" class="name">
						<label for="nomeComprador"><g:message code="pedido.nomeComprador.label" default="Nome Comprador" /></label>
					</td>
					<td valign="top" class="value ${hasErrors(bean: pedidoInstance, field: 'nomeComprador', 'errors')}">
						<g:textField name="nomeComprador" value="${session.cliente}" disabled="yes" />
						<g:hiddenField name="nomeComprador" value="${session.cliente}" />
					</td>
				</tr>
			
				<tr class="prop">
					<td valign="top" class="name">
						<label for="numeroCartao"><g:message code="pedido.numeroCartao.label" default="Numero Cartao" /></label>
					</td>
					<td valign="top" class="value ${hasErrors(bean: pedidoInstance, field: 'numeroCartao', 'errors')}">
						<g:textField name="numeroCartao" value="${pedidoInstance?.numeroCartao}" />
					</td>
				</tr>
				<!--
				<tr class="prop">
					<td valign="top" class="name">
						<label for="oferta"><g:message code="pedido.oferta.label" default="Oferta" /></label>
					</td>
					<td valign="top" class="value ${hasErrors(bean: pedidoInstance, field: 'oferta', 'errors')}">
						<g:select name="oferta.id" from="${baratopradedeu.Oferta.list()}" optionKey="id" value="${pedidoInstance?.oferta?.titulo}"  />
					</td>
				</tr>
				-->
				<tr class="prop">
					<td valign="top" class="name">
						<label for="qtdCupom"><g:message code="pedido.qtdCupom.label" default="Qtd Cupom" /></label>
					</td>
					<td valign="top" class="value ${hasErrors(bean: pedidoInstance, field: 'qtdCupom', 'errors')}">
						<g:textField name="qtdCupom" value="${fieldValue(bean: pedidoInstance, field: 'qtdCupom')}" />
					</td>
				</tr>
			
				<tr class="prop">
					<td valign="top" class="name">
						<label for="valor"><g:message code="pedido.valor.label" default="Valor" /></label>
					</td>
					<td valign="top" class="value ${hasErrors(bean: pedidoInstance, field: 'valor', 'errors')}">
						<g:textField name="valor" value="${ofertaInstance.valorDesconto}" disabled="yes" />
						<g:hiddenField name="valor" value="${ofertaInstance.valorDesconto}" />
					</td>
				</tr>

          </tbody>
        </table>
      </div>
	  
	  <div class="buttons">			
			<span class="button"><g:submitButton name="salvarCompra" class="save" value="${message(code: 'default.button.comprar.label', default: 'salvarCompra')}" /></span>
			 </div>
    </g:form>

  </div>
</body>
</html>